
from selenium import webdriver         # 导包
from selenium.webdriver.common.by import By
import time


class Searchweather:
    def __init__(self):        #初始化对象属性
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
    def search(self):          # 定义搜索方法
        self.driver.get("https://www.sogou.com/")  #打开搜狗首页
        self.driver.find_element(By.ID,"query").send_keys("天气预报")    # 定位输入框输入天气预报
        self.driver.find_element(By.ID,"stb").click()                   #定义搜索按钮,并点击
    def quit(self):
        time.sleep(3)
        self.driver.quit()
# 调用
if __name__ == '__main__':
    sw = Searchweather()
    sw.search()
    time.sleep(3)
    sw.quit()
